//
//  MCfenleiViewController.m
//  MCmeituan
//
//  Created by Mc on 15/12/13.
//  Copyright © 2015年 Mc. All rights reserved.
//

#import "MCfenleiViewController.h"
#import "MCLRTablView.h"
#import "MJExtension.h"
#import "MCfenleiData.h"
#import "MCfenleiData.h"

@interface MCfenleiViewController ()<MCLRTablViewDatasource, MCLRTablViewDelegate>

@property (nonatomic, strong) NSArray *fenleiData;

@end

@implementation MCfenleiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpTableView];


}
#pragma mark --设置cell并设置frame
- (void)setUpTableView
{
    MCLRTablView *lrV = [MCLRTablView lrTableview];
    [self.view addSubview:lrV];
    lrV.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    lrV.frame = self.view.bounds;
    
    lrV.fenleiData = self.fenleiData;
    
    lrV.datasource = self;
    
    lrV.delegate = self;
    
}

- (NSArray *)fenleiData
{
    if (_fenleiData == nil) {
        _fenleiData = [MCfenleiData objectArrayWithFilename:@"categories.plist"];
    }
    return _fenleiData;
}


#pragma mark --代理方法required
- (NSArray *)lrTableView:(MCLRTablView *)lrTableView subDataInlLeftRow:(NSInteger)lRow
{
     MCfenleiData *fenleiData = self.fenleiData[lRow];
    
    return fenleiData.subcategories;
    
}

- (NSString *)lrTableView:(MCLRTablView *)lrTableView titleInLeftRow:(NSInteger)lRow
{
    
    MCfenleiData *fenleiData = self.fenleiData[lRow];
    
    return fenleiData.name;
}

- (NSInteger)numberOfRowsInSection:(MCLRTablView *)lrTableView
{
    return self.fenleiData.count;
}


#pragma mark -代理方法optioal
- (NSString *)lrTableView:(MCLRTablView *)lrTableView iconInLeftRow:(NSInteger)lRow
{
    MCfenleiData *fenleiData = self.fenleiData[lRow];
    
    return fenleiData.icon;
}

- (NSString *)lrTableView:(MCLRTablView *)lrTableView hightlightIconInLeftRow:(NSInteger)lRow
{
    MCfenleiData *fenleiData = self.fenleiData[lRow];
    
    return fenleiData.highlighted_icon;
}

- (void)lrTableView:(MCLRTablView *)lrTableView leftDidSelect:(NSInteger)leftRow andRightRow:(NSInteger)rightRow
{
    MCfenleiData *fenleiData = self.fenleiData[leftRow];
    
    NSString *fenleiStr = fenleiData.subcategories[rightRow];
    
    NSDictionary *fenleiDict = @{
                                 @"MCLeftRow" : fenleiData ,
                                 @"MCRightRow" : fenleiStr
                                 };
    [[NSNotificationCenter defaultCenter] postNotificationName:@"MCfenleiNSNotification" object:self userInfo:fenleiDict];
}
@end
